#include<bits/stdc++.h>
using namespace std;
namespace IO {
	constexpr auto maxn = 1 << 20;
	char in[maxn], out[maxn],*p1 = in,*p2 = in,*p3 = out;
	#define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,maxn,stdin),p1==p2)?EOF:*p1++)
	#define flush() (fwrite(out,1,p3-out,stdout))
	#define putchar(x) (p3==out+maxn&&(flush(),p3=out),*p3++=(x))
	class Flush {
	public:
		~Flush() {
			flush();
		}
	} _;

	namespace usr {
		template<typename type>
		inline type read(type &x) {
			x = 0;
			bool flag(0);
			char ch = getchar();
			while (!isdigit(ch)) flag ^= ch == '-', ch = getchar();
			while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
			return flag ? x = -x : x;
		}
		template<typename type>
		inline void write(type x) {
			x < 0 ? x = -x, putchar('-') : 0;
			static short Stack[50], top(0);
			do Stack[++top] = x % 10, x /= 10;
			while (x);
			while (top) putchar(Stack[top--] | 48);
		}
		inline char read(char &x) {
			do x = getchar();
			while (isspace(x));
			return x;
		}
		inline char write(const char &x) {
			return putchar(x);
		}
		inline void read(char *x) {
			static char ch;
			read(ch);
			do *(x++) = ch;
			while (!isspace(ch = getchar()) && ~ch);
		}
		template<typename type>inline void write(type *x) {
			while (*x)putchar(*(x++));
		}
		inline void read(string &x) {
			static char ch;
			read(ch), x.clear();
			do x += ch;
			while (!isspace(ch = getchar()) && ~ch);
		}
		inline void write(const string &x) {
			for (int i = 0, len = x.length(); i < len; ++i)putchar(x[i]);
		}
		template<typename type, typename...T>inline void read(type &x, T&...y) {
			read(x), read(y...);
		}
		template<typename type, typename...T>
		inline void write(const type &x, const T&...y) {
			write(x), putchar(' '), write(y...), sizeof...(y) ^ 1 ? 0 : putchar('\n');
		}
		template<typename type>
		inline void put(const type &x, bool flag = 1) {
			write(x), flag ? putchar('\n') : putchar(' ');
		}
	}
#undef getchar
#undef flush
#undef putchar
} using namespace IO::usr;
const int N=2e5+10,B=1024;
int n,q,u,v,w,dep[N],fa[N],siz[N],son[N],top[N],dfn[N],rnk[N],cnt,st[20][N],L[N],bid[N],bl[N],br[N],a[N],tot,nxt[N/B+10][N];
long long sum[N],ans,p,l,r;
struct node{
	int v,w;
};
vector<node> edge[N];
inline void dfs1(int u){
	siz[u]=1;
	for(auto &i:edge[u])
		if(!dep[i.v]){
			dep[i.v]=dep[u]+1,fa[i.v]=u,sum[i.v]=sum[u]+i.w;
			dfs1(i.v);
			siz[u]+=siz[i.v];
			if(siz[i.v]>siz[son[u]]) son[u]=i.v;
		}
}
inline void dfs2(int u,int t){
	top[u]=t,dfn[u]=++cnt,rnk[cnt]=u;
	if(son[u]) dfs2(son[u],t);
	for(auto &i:edge[u])
		if(i.v!=fa[u]&&i.v!=son[u]) dfs2(i.v,i.v);
}
inline int lca(int u,int v){
	while(top[u]!=top[v]){
		if(dep[top[u]]<dep[top[v]]) swap(u,v);
		u=fa[top[u]];
	}
	if(dep[u]>dep[v]) swap(u,v);
	return u;
}
inline int mn(int x,int y){
	if(dep[x]<dep[y]) return x;
	return y;
}
inline int mx(int x,int y){
	if(dep[x]>dep[y]) return x;
	return y;
}
inline int lcaq(int l,int r){
	if(l==r) return l;
	r--;
	int s=L[r-l+1];
	return mn(st[s][l],st[s][r-(1<<s)+1]);
}
inline int isson(int x,int y){
	if(dfn[y]>=dfn[x]&&dfn[y]<=dfn[x]+siz[x]-1) return 1;
	return 0;
}
inline long long getans(int x,int y){
	if(dep[x]>dep[y]) swap(x,y);
	if(isson(x,y)) return sum[y]-sum[x];
	int lc=lca(x,y);
	return sum[x]+sum[y]-sum[lc]*2;
}
inline pair<int,int> work(int l,int r,int p){
	int res1=1e9,res2=0;
	if(bid[l]==bid[r]){
		for(int i=l;i<=r;i++){
			if(dfn[i]>=p) res1=min(res1,dfn[i]);
			else res2=max(res2,dfn[i]);
		}
	}else{
		for(int i=bid[l]+1;i<bid[r];i++){
			int now=nxt[i][p];
			if(now<=br[i]) res1=min(res1,a[now]);
			if(now-1>=bl[i]) res2=max(res2,a[now-1]);
		}
		for(int i=l;i<=br[bid[l]];i++){
			if(dfn[i]>=p) res1=min(res1,dfn[i]);
			else res2=max(res2,dfn[i]);
		}
		for(int i=bl[bid[r]];i<=r;i++){
			if(dfn[i]>=p) res1=min(res1,dfn[i]);
			else res2=max(res2,dfn[i]);
		}
	}
	int ret1=1,ret2=1;
	if(res1<1e9) ret1=rnk[res1];
	if(res2!=0) ret2=rnk[res2];
	return {ret1,ret2};
}
inline long long solve(int p,int l,int r){
	int res=lcaq(l,r);
	if(isson(res,p)){
		auto s=work(l,r,dfn[p]);
		return getans(p,mx(lca(s.first,p),lca(s.second,p)));
	}else return getans(res,p);
}
signed main(){
	freopen("memory.in","r",stdin);
	freopen("memory.out","w",stdout);
	read(n,q);
	for(int i=2;i<=n;i++)
		L[i]=L[i/2]+1;
	for(int i=1;i<=n;i++)
		bid[i]=(i-1)/B+1;
	for(tot=1;tot<=1000;tot++){
		bl[tot]=(tot-1)*B+1,br[tot]=min(n,tot*B);
		if(br[tot]==n) break;
	}
	for(int i=1;i<n;i++){
		read(u,v,w);
		edge[u].push_back({v,w}),edge[v].push_back({u,w});
	}
	dep[1]=1;
	dfs1(1),dfs2(1,1);
	for(int i=1;i<n;i++)
		st[0][i]=lca(i,i+1);
	for(int i=1;i<20;i++)
		for(int j=1;j<n;j++)
			if(j+(1<<i)-1<n) st[i][j]=mn(st[i-1][j],st[i-1][j+(1<<(i-1))]);
	for(int i=1;i<=n;i++)
		a[i]=dfn[i];
	for(int i=1;i<=tot;i++){
		sort(a+bl[i],a+br[i]+1);
		int lst=-1;
		for(int j=bl[i];j<=br[i];j++){
			for(int k=lst+1;k<=a[j];k++)
				nxt[i][k]=j;
			lst=a[j];
		}
		for(int j=lst+1;j<=n;j++)
			nxt[i][j]=br[i]+1;
	}
	while(q--){
		read(p,l,r);
		p^=ans,l^=ans,r^=ans;
		ans=solve(p,l,r);
		write(ans),write('\n');
	}
	return 0;
}